let app = getApp();
const { getUserInfo } = require('../../../common/utils/ws/wsxcx-opendata-sdk');

Page({

  data: {
    list: [],
    money: '0.00'
  },

  onLoad: function (options) {
    let that = this;
    that.setData({
      id: options.id,
    }, () => {
      getUserInfo()
        .then(userInfo => {
          that.setData({ userInfo });
          that.getActivity();
          that.getReceiveList();
        });
    });
  },

  getActivity () {
    let that = this;
    let { id } = this.data;
    app.util.request({
      data: { id },
      url: 'wechatWork/redpacket/getActivity',
      success: (res) => {
        let { errno, data } = res.data;
        if (Number(errno) === 0) {
          that.setData({
            money: data.money
          });
        }
      },
    });
  },

  getReceiveList () {
    let that = this;
    let { id } = that.data;
    app.util.request({
      data: { id },
      url: 'wechatWork/redpacket/getReceiveList',
      success: (res) => {
        console.log('领取记录列表：', res);
        let { errno, data } = res.data;
        if (Number(errno) === 0) {
          that.setData({
            list: data,
          });
        }
      },
    });
  },
});